﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LogToDB
{
    class CommonFuction
    {


        public static string GetFileMessage<T>(LogInst inst)
        {
            string message = "";
            string value = string.Empty;
            System.Type vType = typeof(T);
            System.Reflection.FieldInfo[] vFieldInfos = vType.GetFields();
            for (int i = 0; i < vFieldInfos.Length; i++)
            {

                System.Reflection.FieldInfo vFieldInfo = vFieldInfos[i];
                try
                {
                    string column = Convert.ToString(vFieldInfo.Name);

                    string colType = Convert.ToString(vFieldInfo.FieldType);
                    object colValue = vFieldInfo.GetValue(inst);
                    colType = MysqlDB.GetDBTypeByType(colType);
                    if (string.IsNullOrEmpty(colType))
                    {
                        continue;
                    }

                    if (colValue == null)
                        colValue = "NULL";
                 
                    
                    message = message + "@"+colValue;


                }
                catch (System.Exception e)
                {
                    Util.WriteLog(e.ToString());
                }
            }
            return message;
        }
     
    }
}
